#import "ALEventView.h"


#pragma mark Class Globals

static NSGradient *ALEventViewBackgroundGradient;
static NSColor *ALEventViewBorderColor;
static NSGradient *ALEventViewBackgroundGradientSelected;
static NSColor *ALEventViewBorderColorSelected;
static NSColor *ALEventViewHighlightColorSelected;


#pragma mark -
@implementation ALEventView

@synthesize selected;
@synthesize bottomBorderColor;


+(void)initialize {
	NSColor *topColor = [NSColor colorWithCalibratedWhite:1.000 alpha:1.000];
	NSColor *bottomColor = [NSColor colorWithCalibratedWhite:0.970 alpha:1.000];
	ALEventViewBackgroundGradient = [[NSGradient alloc] initWithStartingColor:topColor endingColor:bottomColor];
	ALEventViewBorderColor = [NSColor colorWithCalibratedWhite:0.899 alpha:1.000];
	
	NSColor *topColorSelected = [NSColor colorWithCalibratedRed:0.761 green:0.812 blue:0.898 alpha:1.000];
	NSColor *bottomColorSelected = [NSColor colorWithCalibratedRed:0.595 green:0.699 blue:0.822 alpha:1.000];
	ALEventViewBackgroundGradientSelected = [[NSGradient alloc] initWithStartingColor:topColorSelected endingColor:bottomColorSelected];
	ALEventViewBorderColorSelected = [NSColor colorWithCalibratedRed:0.473 green:0.526 blue:0.606 alpha:1.000];
	ALEventViewHighlightColorSelected = [NSColor colorWithCalibratedWhite:1.000 alpha:0.390];
}

-(void)drawRect:(NSRect)dirtyRect {
	NSRect bounds = [self bounds];
	NSGradient *backgroundGradient = [self selected] ? ALEventViewBackgroundGradientSelected : ALEventViewBackgroundGradient;
	NSBezierPath *framePath = [NSBezierPath bezierPathWithRect:bounds];
	[backgroundGradient drawInBezierPath:framePath angle:270.0f];
	
	bounds = NSInsetRect(bounds, 0, 0.5);
	CGFloat minx = NSMinX(bounds);
	CGFloat maxx = NSMaxX(bounds);
	CGFloat miny = NSMinY(bounds);
	[[self bottomBorderColor] setStroke];
	[NSBezierPath strokeLineFromPoint:NSMakePoint(minx, miny) toPoint:NSMakePoint(maxx, miny)];
	
	if (![self selected])
		return;

	CGFloat maxy = NSMaxY(bounds);
	[ALEventViewHighlightColorSelected setStroke];
	[NSBezierPath strokeLineFromPoint:NSMakePoint(minx, maxy) toPoint:NSMakePoint(maxx, maxy)];
}

@end
